package cn.itcast.service.company.impl;

import cn.itcast.dao.company.CompanyDao;
import cn.itcast.domain.company.Company;
import cn.itcast.service.company.CompanyService;
import cn.itcast.vo.PageResult;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.UUID;

@Service
public class CompanyServiceImpl implements CompanyService {

 @Autowired
 private CompanyDao companyDao;

 //查询全部
 public List<Company> findAll() {
  return companyDao.findAll();
 }

 //保存
 public void save(Company company) {
  company.setId(UUID.randomUUID().toString());
  companyDao.save(company);
 }

 //根据id查询
 public Company findById(String id) {
  return companyDao.findById(id);
 }

 //更新
 public void update(Company company) {
  companyDao.update(company);
 }

 //删除
 public void delete(String id) {
  companyDao.delete(id);
 }

 //传统分页
 public PageResult findPage(int page, int size) {
  //分页的总记录数
  long total = companyDao.findCount();
  //分页查询当前页数据列表
  List list = companyDao.findPage((page-1)*size,size);
  return new PageResult(total,list,page,size);
 }

 /**
  * 通过PageHelper分页
  */
 public PageInfo findPageByHelper(int page, int size) {
  //设置分页参数
  PageHelper.startPage(page, size);
  //调用dao查询全部
  List<Company> list = companyDao.findAll();
  //构造返回值
  return new PageInfo(list);
 }
}
